﻿@model HomePageModel
@{
    var additionalClasses = "";
    if (Model.HideDetails)
    {
        additionalClasses = "initially-hidden";
    }
}

<div class="container-fluid tagline">
    @if (!string.IsNullOrEmpty(Model.CustomDescription))
    {
        <div style="white-space:pre-wrap">@Model.CustomDescription</div>
    }
    else
    {
        @:SAML2 stub: be whoever you want to be
}
</div>

@if (Request.Url.Host == "stubidp.kentor.se")
{
    <div class="container">
        <div class="col-md-12">
            <div class="panel panel-warning">
                <div class="panel-heading">
                    Service moved to <a href="https://stubidp.sustainsys.com">https://stubidp.sustainsys.com</a>
                </div>
                <div class="panel-body">
                    This service has moved to <a href="https://stubidp.sustainsys.com">https://stubidp.sustainsys.com</a>. The
                    stubidp.kentor.se host name will be removed, please update your configuration. All custom tenant information
                    is the same accross the domain names.
                </div>
            </div>
        </div>
    </div>
}

@if (Request.Url.Host == "stubidp.sustainsys.com" && Request.Url.Scheme == "http")
{
    <div class="container">
        <div class="col-md-12">
            <div class="panel panel-info">
                <div class="panel-heading">
                    Consider using <a href="https://stubidp.sustainsys.com">https://stubidp.sustainsys.com</a> instead
                </div>
                <div class="panel-body">
                    You are currently accessing this service unencrypted. Consider changing to use the https version instead.
                </div>
            </div>
        </div>
    </div>
}

<div class="container">
    <div class="col-lg-8 card">
        <h2>Send SAML2 Response</h2>
        <div class="contents">
            <p>
                This form will send a SAML2 Response to a service provider. If the In Response To ID
                field is empty, the Response is considered unsolicited (IDP initiated).
            </p>
            <p>
                The pre-filled values in the user selection box are just an example. If you
                want to build your own user list you can
                @Html.ActionLink("create your own IDP tenant", "Index", "Manage", new { idpId = Guid.NewGuid() }, null).
            </p>
            @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = additionalClasses }))
            {
                @Html.HiddenFor(m => m.CustomDescription) @*Preserve value on post-redisplay*@
                <div id="user-dropdown-placeholder" class="form-group row" style="display:none">
                    <label for="userList" class="col-form-label col-sm-4">Use pre-filled values</label>
                    <div class="col-md-8">
                        <select id="userList"></select>
                    </div>
                    <div class="col-md-8" id="userDescription">&nbsp;</div>
                </div>

                if (Model.AssertionModel.AuthnRequestXml != null)
                {
                    <div class="hide-details form-group row">
                        <label class="col-form-label col-md-4">@Html.DisplayNameFor(m => m.AssertionModel.AuthnRequestXml)</label>
                        <div class="col-md-8">
                            <pre class="xml">@Model.AssertionModel.AuthnRequestXml</pre>
                        </div>
                    </div>
                }

                <div class="hide-details form-group row">
                    @Html.LabelFor(m => m.AssertionModel.InResponseTo, new { @class = "col-form-label col-md-4" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(m => m.AssertionModel.InResponseTo, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.AssertionModel.InResponseTo)
                    </div>
                </div>

                <div class="hide-details form-group row">
                    @Html.LabelFor(m => m.AssertionModel.AssertionConsumerServiceUrl, new { @class = "col-form-label col-md-4" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(m => m.AssertionModel.AssertionConsumerServiceUrl, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.AssertionModel.AssertionConsumerServiceUrl)
                    </div>
                </div>

                <div class="hide-details form-group row">
                    @Html.LabelFor(m => m.AssertionModel.Audience, new { @class = "col-form-label col-md-4" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(m => m.AssertionModel.Audience, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.AssertionModel.Audience)
                    </div>
                </div>

                <div class="hide-details form-group row">
                    <label class="col-form-label col-md-4">Send response via</label>
                    <div class="radio-group col-md-8">
                        <label for="binding_post">
                            <input type="radio" name="AssertionModel.ResponseBinding" id="binding_post"
                                   checked="@(Model.AssertionModel.ResponseBinding == Sustainsys.Saml2.WebSso.Saml2BindingType.HttpPost)"
                                   value="HttpPost" />
                            Http POST Binding
                        </label>
                        <label for="binding_artifact">
                            <input type="radio" name="AssertionModel.ResponseBinding" id="binding_artifact"
                                   checked="@(Model.AssertionModel.ResponseBinding == Sustainsys.Saml2.WebSso.Saml2BindingType.Artifact)"
                                   value="Artifact" />
                            Artifact Binding over Http Redirect
                        </label>
                    </div>
                </div>

                <div class="hide-details form-group row">
                    @Html.LabelFor(m => m.AssertionModel.RelayState, new { @class = "col-form-label col-md-4" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(m => m.AssertionModel.RelayState, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.AssertionModel.RelayState)
                    </div>
                </div>

                <div class="hide-details form-group row">
                    @Html.LabelFor(m => m.AssertionModel.NameId, new { @class = "col-form-label col-md-4" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(m => m.AssertionModel.NameId, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.AssertionModel.NameId)
                    </div>
                </div>

                <div class="hide-details form-group row">
                    @Html.LabelFor(m => m.AssertionModel.SessionIndex, new { @class = "col-form-label col-md-4" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(m => m.AssertionModel.SessionIndex, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.AssertionModel.SessionIndex)
                    </div>
                </div>

                <div class="hide-details panel panel-default">
                    <div class="panel-heading">Attribute Statements</div>
                    <div class="panel-body">
                        <div id="attributes-placeholder" class="row" style="display:none">
                            <label class="col-md-5 hidden-sm hidden-xs">Type</label>
                            <label class="col-md-5 hidden-sm hidden-xs">Value</label>
                        </div>
                        <button class="btn glyphicon glyphicon-plus" id="add-attribute"></button>
                    </div>
                </div>
                <p></p>
                <button class="btn btn-primary" id="submit">Log in</button>
                <button class="show-details btn btn-secondary">Show Details</button>
            }

        </div>
    </div>
    @Html.Partial("_About")
</div>


<script id="attributeRowTemplate" type="text/html">
    @* Mustache.js template for each attribute row *@
    @*Array model binding using Index property, see http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/*@
    <div class="attribute-row form-group">
        <input type="hidden" name="AssertionModel.AttributeStatements.Index" value="{{rowIndex}}" />
        <div class="col-md-5">
            <label class="hidden-md hidden-lg col-form-label">Type</label>
            <input class="form-control" type="text" data-val="true" data-val-required="The Type field is required." name="AssertionModel.AttributeStatements[{{rowIndex}}].Type" value="{{type}}" />
        </div>
        <div class="col-md-5">
            <label class="hidden-md hidden-lg col-form-label">Value</label>
            <input class="pull-right form-control" type="text" data-val="true" data-val-required="The Value field is required." name="AssertionModel.AttributeStatements[{{rowIndex}}].Value" value="{{value}}" />
        </div>
        <div class="col-md-1 col-xs-1">
            <button class="btn remove-attribute glyphicon glyphicon-trash"></button>
        </div>
        <div class="col-xs-11 col-md-12">
            <span class="col-md-5 field-validation-valid" data-valmsg-for="AssertionModel.AttributeStatements[{{rowIndex}}].Type" data-valmsg-replace="true"></span>
            <span class="col-md-5 field-validation-valid" data-valmsg-for="AssertionModel.AttributeStatements[{{rowIndex}}].Value" data-valmsg-replace="true"></span>
        </div>
    </div>
</script>

@* Mustache.js template for a user item display in the select2 list *@
<script id="userListTemplate" type="text/html">
    <div>
        {{DisplayName}}
        <br />
        <em>
            {{Description}}
        </em>
    </div>
</script>
